import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int a = 0;
        int b = 1;
        int c = 1;

        int ret = n-1;

        while(true) {
            if(c > n) {
                ret = Math.min(ret,Math.abs(c-n));
                break;
            }
            c = a+b;
            ret = Math.min(ret,Math.abs(c-n));
            a = b;
            b = c;
        }
        System.out.println(ret);
    }
}